package com.yikome.config;

import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
 
	private static final int PMP_MAX_PAGE_SIZE = 10000;
	
	@Override
	 public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
		
        PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
 
        resolver.setMaxPageSize(PMP_MAX_PAGE_SIZE);
        resolver.setOneIndexedParameters(true);
        argumentResolvers.add(resolver);
    }
	
	@Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedOrigins("*")
            .allowCredentials(true)
            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
            .maxAge(3600);
    }
}